package git.soulbgm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import git.soulbgm.mapper.DictTypeMapper;
import git.soulbgm.pojo.DictType;
import git.soulbgm.service.DictTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 字段类型服务实现类
 *
 * @author SoulBGM
 * @date 2022/03/25 16:53
 */
@Service("dictType")
public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, DictType> implements DictTypeService {

    /**
     * 获得所有字典类型
     *
     * @return {@link List}<{@link DictType}>
     */
    @Override
    public List<DictType> getType() {
        return list(new LambdaQueryWrapper<DictType>().select(DictType::getDictName, DictType::getDictType));
    }

    /**
     * 校验唯一
     *
     * @param info 字典类型数据
     * @return {@link Boolean}
     */
    @Override
    public Boolean checkUnique(DictType info) {
        return count(new LambdaQueryWrapper<DictType>()
                .ne(info.getId() != null, DictType::getId, info.getId())
                .eq(DictType::getDictType, info.getDictType())) == 0;
    }

}
